class Solution {
public:
      static bool cmp(const vector<int>& a,const vector<int>& b){
          if(a[0] == b[0]) return a[1] > b[1];
          return a[0] > b[0];
      }  
    
    int Max_N = 101;
    vector<int> c;
    int lowBit(int x){
        return x & (-x);
    }
    int query(int p){
        int ret = 0;
        while(p > 0){
            ret += c[p];
            p -= lowBit(p);
        }
        return ret;
    }
    void update(int p){
        while(p < c.size()){
            c[p] += 1;
            p += lowBit(p);
        }
    }
    
    vector<int> countRectangles(vector<vector<int>>& rectangles, vector<vector<int>>& points) {
        c.resize(Max_N);
        sort(rectangles.begin(),rectangles.end(),cmp);
        
        for(int i = 0;i < points.size();i++){
            points[i].push_back(i);
        }
        sort(points.begin(),points.end(),cmp);
        
        int n = rectangles.size();
        int Max = 0;
        for(int i = 0;i < n; i++){
            Max = max(Max,rectangles[i][1]);
        }
        
        int recX = 0;
        vector<int> ret(points.size());
        for(int i = 0;i < points.size();i++){
            if(points[i][1] > Max) continue;
            while(recX < n && points[i][0] <= rectangles[recX][0]){
                update(rectangles[recX][1]);
                recX++;
            }
            ret[points[i][2]] = query(100) - query(points[i][1]-1);
        }
        return ret;
    }
};
